package com.gaolu;

import java.io.InputStream;
import java.util.Properties;

import javax.sql.DataSource;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

public class MyDataSourceFactory {
	public static DataSource getMysqlDataSource() throws Exception {
		Properties props = new Properties();
		InputStream fileInputStream = MyDataSourceFactory.class.getClassLoader().getResourceAsStream("db.properties");
		props.load(fileInputStream);
		
		MysqlDataSource mysqlDataSource = new MysqlDataSource();
		mysqlDataSource.setURL(props.getProperty("MYSQL_DB_URL"));
		mysqlDataSource.setUser(props.getProperty("MYSQL_DB_USERNAME"));
		mysqlDataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD"));
		return mysqlDataSource;
	}
}
